package com.zxp.web.sys_role_menu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxp.web.sys_role_menu.entity.SaveMenuParam;
import com.zxp.web.sys_role_menu.entity.SysRoleMenu;
import com.zxp.web.sys_role_menu.mapper.SysRoleMenuMapper;
import com.zxp.web.sys_role_menu.service.SysRoleMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author MasterZ
 * @Date 2025/10/5 12:49
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveRoleMenu(SaveMenuParam param) {
        //先删除
        QueryWrapper<SysRoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysRoleMenu::getRoleId, param.getRoleId());
        this.remove(queryWrapper);
        //再保存
        this.baseMapper.saveRoleMenu(param.getRoleId(), param.getMenuIds());
    }
}
